<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <body>
        <ui:composition template="./template/News_Template.xhtml">
            <ui:define name="content">
                <h:messages showDetail="true" showSummary="false"
                            style="list-style: none;border-style: solid;border-width: 1px;border-color: red;padding: 5px 5px 5px 5px;background-color: #eba4a4;color: #ff0000"
                            id="getnews-mesage"/>
                <h:form id="new1">
                    <h:outputText value="Source list : "/>
                    <p:dataTable value="#{getNews.sources}" emptyMessage="Chua co ban ghi nao"
                                 var="source" selection="#{getNews.selected}">
                        <p:column selectionMode="single"/>  
                        <p:column headerText="Logo" style="width: 20px">
                            <h:graphicImage value="#{source.photo}"/>
                        </p:column>
                        <p:column headerText="Tên">
                            <h:outputText value="#{source.name}"/>
                        </p:column>
                    </p:dataTable>
                    <br/>
                    <h:commandButton value="Lấy ra các tin mới nhất" action="#{getNews.doGetNews}">
                        <f:ajax render="doAction mess" execute="@form" onevent="showWorkingIndicator"/>
                    </h:commandButton>
                    <hr/>
                    <h:panelGroup id="mess">
                        <h:outputText value="#{getNews.message}"/><br/>
                    </h:panelGroup>
                    <br/>
                    <h:panelGroup id="doAction">
                       
                            <p:dataTable value="#{getNews.newsList}" var="news" 
                                         emptyMessage="Chưa có tin nào được liệt kê !"
                                         style="width: 100%;border-style: none" selection="#{getNews.selectNews}">
                                <p:column>
                                    <table width="100%" style="border-style: none" border="0" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td colspan="2">
                                                <a href="#{news.sourceLink}" target="_blank">
                                                    #{news.title}
                                                </a>
                                               
                                                <h:outputText rendered="#{news.exist}" style="color: red" value="   ( Đã tồn tại trong hệ thống )"/>
                                                   </td>
                                        </tr>
                                        <tr>
                                            <td width="20%"><h:graphicImage value="#{news.photo}"/></td>
                                            <td width="80%" style="vertical-align: top"><h:outputText value="#{news.subContent}"/></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">&nbsp;</td>
                                        </tr>
                                    </table>
                                </p:column>
                                <p:column selectionMode="multiple" />
                            </p:dataTable>
                            <br/>
                            <h:commandButton style="float: right" rendered="#{getNews.flag}"
                                             value="Lấy các tin đã được chọn !" action="#{getNews.doProcess}">
                                <f:ajax render="hihi" execute="@form" onevent="showWorkingIndicator"/>
                            </h:commandButton>
                            <h:panelGroup id="hihi">
                                <h:outputText rendered="#{getNews.flag}" value="#{getNews.url}" style="font-weight: bold"/><br/>
                            </h:panelGroup>

                    </h:panelGroup>
                    <span id="workingIndicator"
                          style="display: none;">
                        <h:graphicImage library="images" name="ajax-loader.gif"/>
                        <br/>
                        <h:outputText value="Đang tải dữ liệu từ máy chủ..."/>
                    </span> 
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
